package com.jing.shop.controller;

import com.github.pagehelper.PageInfo;
import com.jing.common.core.domain.R;
import com.jing.shop.domain.dto.ProductShopDTO;
import com.jing.shop.domain.po.ProductAttributePO;
import com.jing.shop.domain.vo.ProductShopVO;
import com.jing.shop.service.ProductShopService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Api(tags = "商品")
@RestController
@RequestMapping("/shop")
public class ProductShopController {

    private static final Logger log = LoggerFactory.getLogger(ProductAttributeCategoryController.class);

    @Autowired
    private ProductShopService productShopService;

//    @ApiOperation("商品列表展示")
//    @PostMapping("/page")
//    public R page(@RequestBody ProductShopDTO productShopDTO){
//        PageInfo<ProductShopVO> shopList = productShopService.findShopList(productShopDTO);
//        return R.ok(shopList);
//    }

    @ApiOperation(value = "商品添加")
    @PostMapping("/add")
    public R add(@RequestBody ProductShopDTO productShopDTO){
        productShopService.addShop(productShopDTO);
        return R.ok();
    }

    @ApiOperation(value = "商品修改")
    @PostMapping("/updateShop")
    public R updateShop(@RequestBody ProductShopDTO productShopDTO){
        productShopService.updateShop(productShopDTO);
        return R.ok();
    }

    @ApiOperation(value = "商品删除")
    @PostMapping("/update")
    public R update(@RequestBody ProductShopDTO productShopDTO){
        productShopService.update(productShopDTO);
        return R.ok();
    }

    @ApiOperation(value = "图片上传")
    public R upload(@RequestParam("file")MultipartFile multipartFile){
        R upload = productShopService.upload(multipartFile);
        return upload;
    }

    @ApiOperation(value = "商品参数")
    @GetMapping("/findAttr/{categoryId}")
    public R findAttr(@PathVariable Integer categoryId){
        List<ProductAttributePO> attr = productShopService.findAttr(categoryId);
        return R.ok(attr);
    }

}
